package com.ruoyi.system.controller;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.ArchiveDigitizationStat;
import com.ruoyi.system.service.ArchiveDigitizationStatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 档案数字化统计 Controller
 *
 * @author 你的名字
 */
@RestController
@RequestMapping("/system/archiveDigitizationStat")
public class ArchiveDigitizationStatController {
    @Autowired
    private ArchiveDigitizationStatService archiveDigitizationStatService;

    /**
     * 查询档案数字化统计列表
     */
    @GetMapping("/list")
    public AjaxResult list(ArchiveDigitizationStat archiveDigitizationStat) {
        List<ArchiveDigitizationStat> list = archiveDigitizationStatService.selectArchiveDigitizationStatList(archiveDigitizationStat);
        List<List<Object>> tableData = new ArrayList<>();
        Map map = new HashMap();
        if(list != null && list.size() > 0)
        {
            for (ArchiveDigitizationStat digitizationStat : list) {
                List<Object> datas = new ArrayList<>();
                datas.add(digitizationStat.getName());
                datas.add(digitizationStat.getValue());
                datas.add(digitizationStat.getItemCount());
                datas.add(digitizationStat.getDigitizedCount());
                datas.add(digitizationStat.getDigitizationRate());
                tableData.add(datas);
            }
        }
        map.put("tableData",tableData);
        map.put("list",list);
        return AjaxResult.success(map);
    }

    /**
     * 获取档案数字化统计详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(archiveDigitizationStatService.selectArchiveDigitizationStatById(id));
    }

    /**
     * 新增档案数字化统计
     */
    @PostMapping
    public AjaxResult add(@RequestBody ArchiveDigitizationStat archiveDigitizationStat) {
        return AjaxResult.success(archiveDigitizationStatService.insertArchiveDigitizationStat(archiveDigitizationStat));
    }

    /**
     * 修改档案数字化统计
     */
    @PutMapping
    public AjaxResult edit(@RequestBody ArchiveDigitizationStat archiveDigitizationStat) {
        return AjaxResult.success(archiveDigitizationStatService.updateArchiveDigitizationStat(archiveDigitizationStat));
    }

    /**
     * 删除档案数字化统计
     */
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return AjaxResult.success(archiveDigitizationStatService.deleteArchiveDigitizationStatByIds(ids));
    }

    /**
     * 批量保存档案数字化统计（先删后插）
     */
    @PostMapping("/batchSave")
    public AjaxResult batchSave(@RequestBody List<ArchiveDigitizationStat> list) {
        return AjaxResult.success(archiveDigitizationStatService.batchSaveArchiveDigitizationStat(list));
    }
}